package springboot.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springboot.domain.User;
import springboot.mapper.UserMapper;
import springboot.service.IUserService;

import java.util.List;

@Service
@Log4j2
public class UserService implements IUserService {

//    @Autowired
    private UserMapper userMapper;

//    @Autowired
    private ObjectMapper objectMapper;

//    public UserService(UserMapper userMapper, ObjectMapper objectMapper) {
//        this.userMapper = userMapper;
//        this.objectMapper = objectMapper;
//    }

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Autowired
    public void setObjectMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    public void listAll() throws JsonProcessingException {
        List<User> userList = userMapper.selectList(null);
        log.info("log4j-userList={}", objectMapper.writeValueAsString(userList));
    }
}
